﻿unit SearchFiles;

interface

uses
  Classes,SysUtils,FileInfo,Dialogs;

var
  MyFileInfo : PFileInfo;
  I:Integer;
  StrFile : string;

function FirstSearch(var ResultList:TStringList;FileList:TList;SN:string):Integer;

function SecondSearch(var ResultList:TStringList;FileList:TList;SN:string):Integer;

implementation

//精确查找
function FirstSearch(var ResultList:TStringList;FileList:TList;SN:string):Integer;
begin
  ResultList.Clear;
  for I := 0 to FileList.Count - 1 do
  begin
    MyFileInfo := FileList[I];
    if ansicomparestr(MyFileInfo.FileName,SN)=0 then
    begin
      StrFile := concat(IntToStr(I),'=',MyFileInfo.FileName,',',
              MyFileInfo.FilePath,',',MyFileInfo.FileType,',',IntToStr(MyFileInfo.FileSize),'KB,',MyFileInfo.FileDate);
      ResultList.Add(StrFile);

    end;
  end;
  Result := ResultList.Count;
end;

//模糊查找
function SecondSearch(var ResultList:TStringList;FileList:TList;SN:string):Integer;
begin
  ResultList.Clear;
  for I := 0 to FileList.Count - 1 do
  begin
    MyFileInfo := FileList[I];
    if POS(SN,MyFileInfo.FileName)>0 then
    begin
      StrFile := concat(IntToStr(I),'=',MyFileInfo.FileName,',',
              MyFileInfo.FilePath,',',MyFileInfo.FileType,',',IntToStr(MyFileInfo.FileSize),'KB,',MyFileInfo.FileDate);
      ResultList.Add(StrFile);
    end;
  end;
  Result := ResultList.Count;
end;


end.
